﻿using System;
using UnityEngine;
using System.Collections.Generic;

/// <summary>
/// Tick manager.时间管理器
/// </summary>
public class TickManager:MonobeSingleTon<TickManager>
{
	List<Tick> m_TickList = new List<Tick> ();
	public TickManager ()
	{
	}
	public void addTick(Tick tick)
	{
		if(null == m_TickList) return;
		m_TickList.Add (tick);
	}
	float   m_LastTime  = 0.0f;
	void  Update()
	{
		if(null == m_TickList) return;
		float nowTime;
		nowTime = Time.time;
		float  timeElapsed = nowTime - m_LastTime;
		m_LastTime = nowTime; 
		int len = m_TickList.Count;
		Tick tick;
		for(int i = len - 1; i >= 0; i--) 
		{
			tick = m_TickList[i];
			if(tick != null && !tick.isEnd())
			{
				tick.onTick((int)(timeElapsed * 1000));
			}
			else 
			{
				m_TickList.RemoveAt (i);
			}
		}
	}
}

